#include "monitorthread.h"
/*可行修改中*/

MonitorThread::MonitorThread(QObject* parent)
    : QThread(parent), denominator_(1)
{
}

void MonitorThread::setFraction(int denominator, QProgressBar* progressBar) //设置分母和进度条指针
{
    denominator_ = denominator;
    progressBar_ = progressBar;
}

void MonitorThread::run()
{
    // numerator_ = getGlobal();
    // 创建进度条对话框
//    progressDialog_ = new QProgressDialog("Progress", "Cancel", 0, 100);
//    progressDialog_->setAttribute(Qt::WA_NativeWindow, false);
//    progressDialog_->setRange(0, 100);
//    progressDialog_->setWindowTitle("Progress");
//    progressDialog_->setWindowModality(Qt::WindowModal);
//    progressDialog_->setMinimumDuration(1);
//    progressDialog_->show();
//    progressDialog_->setValue(0);
//    // 连接信号与槽函数，更新进度条的值
//    connect(this, &MonitorThread::progressUpdated, progressDialog_, &QProgressDialog::setValue);

    // 监视外部的 num 全局变量，并更新进度条的值
    progressBar_->setRange(0, denominator_);
    while (written <= denominator_) {
//        qDebug() << written << endl;
        int val = written;
//        emit this->progressUpdated(val);
        progressBar_->setValue(val);
//        msleep(100);  // 线程休眠一段时间，避免频繁更新进度条
        if (val == denominator_) {
            qDebug() << written << endl;
            break;
        }
    }

}
